package edu.del.springbootredisbusinesspractice.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import lombok.Data;

/**
 * 订单主表
 * @TableName orders
 */
@TableName(value ="orders")
@Data
public class Orders implements Serializable {
    /**
     * 订单ID，主键
     */
    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 订单编号，唯一标识，如：ORD202406010001
     */
    private String orderNo;

    /**
     * 商品ID，关联商品表 product.id
     */
    private Long productId;

    /**
     * 用户ID，关联用户表（后续可扩展）
     */
    private Long userId;

    /**
     * 订单总金额
     */
    private BigDecimal totalAmount;

    /**
     * 购买数量，默认为1
     */
    private Integer quantity;

    /**
     * 订单状态：1-待付款，2-已付款，3-已发货，4-已完成，5-已取消
     */
    private Integer status;

    /**
     * 支付方式，如：支付宝、微信、银行卡
     */
    private String paymentMethod;

    /**
     * 收货地址，JSON格式存储详细地址信息
     */
    private String shippingAddress;

    /**
     * 联系电话
     */
    private String contactPhone;

    /**
     * 收货人姓名
     */
    private String contactName;

    /**
     * 下单时间
     */
    private Date createdAt;

    /**
     * 更新时间
     */
    private Date updatedAt;

    /**
     * 支付时间
     */
    private Date paidAt;

    /**
     * 发货时间
     */
    private Date shippedAt;

    /**
     * 完成时间
     */
    private Date completedAt;

    /**
     * 取消时间
     */
    private Date cancelledAt;

    @Serial
    private static final long serialVersionUID = 8984651313213213L;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        Orders other = (Orders) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getOrderNo() == null ? other.getOrderNo() == null : this.getOrderNo().equals(other.getOrderNo()))
            && (this.getProductId() == null ? other.getProductId() == null : this.getProductId().equals(other.getProductId()))
            && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
            && (this.getTotalAmount() == null ? other.getTotalAmount() == null : this.getTotalAmount().equals(other.getTotalAmount()))
            && (this.getQuantity() == null ? other.getQuantity() == null : this.getQuantity().equals(other.getQuantity()))
            && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
            && (this.getPaymentMethod() == null ? other.getPaymentMethod() == null : this.getPaymentMethod().equals(other.getPaymentMethod()))
            && (this.getShippingAddress() == null ? other.getShippingAddress() == null : this.getShippingAddress().equals(other.getShippingAddress()))
            && (this.getContactPhone() == null ? other.getContactPhone() == null : this.getContactPhone().equals(other.getContactPhone()))
            && (this.getContactName() == null ? other.getContactName() == null : this.getContactName().equals(other.getContactName()))
            && (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()))
            && (this.getUpdatedAt() == null ? other.getUpdatedAt() == null : this.getUpdatedAt().equals(other.getUpdatedAt()))
            && (this.getPaidAt() == null ? other.getPaidAt() == null : this.getPaidAt().equals(other.getPaidAt()))
            && (this.getShippedAt() == null ? other.getShippedAt() == null : this.getShippedAt().equals(other.getShippedAt()))
            && (this.getCompletedAt() == null ? other.getCompletedAt() == null : this.getCompletedAt().equals(other.getCompletedAt()))
            && (this.getCancelledAt() == null ? other.getCancelledAt() == null : this.getCancelledAt().equals(other.getCancelledAt()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getOrderNo() == null) ? 0 : getOrderNo().hashCode());
        result = prime * result + ((getProductId() == null) ? 0 : getProductId().hashCode());
        result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
        result = prime * result + ((getTotalAmount() == null) ? 0 : getTotalAmount().hashCode());
        result = prime * result + ((getQuantity() == null) ? 0 : getQuantity().hashCode());
        result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
        result = prime * result + ((getPaymentMethod() == null) ? 0 : getPaymentMethod().hashCode());
        result = prime * result + ((getShippingAddress() == null) ? 0 : getShippingAddress().hashCode());
        result = prime * result + ((getContactPhone() == null) ? 0 : getContactPhone().hashCode());
        result = prime * result + ((getContactName() == null) ? 0 : getContactName().hashCode());
        result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
        result = prime * result + ((getUpdatedAt() == null) ? 0 : getUpdatedAt().hashCode());
        result = prime * result + ((getPaidAt() == null) ? 0 : getPaidAt().hashCode());
        result = prime * result + ((getShippedAt() == null) ? 0 : getShippedAt().hashCode());
        result = prime * result + ((getCompletedAt() == null) ? 0 : getCompletedAt().hashCode());
        result = prime * result + ((getCancelledAt() == null) ? 0 : getCancelledAt().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", orderNo=").append(orderNo);
        sb.append(", productId=").append(productId);
        sb.append(", userId=").append(userId);
        sb.append(", totalAmount=").append(totalAmount);
        sb.append(", quantity=").append(quantity);
        sb.append(", status=").append(status);
        sb.append(", paymentMethod=").append(paymentMethod);
        sb.append(", shippingAddress=").append(shippingAddress);
        sb.append(", contactPhone=").append(contactPhone);
        sb.append(", contactName=").append(contactName);
        sb.append(", createdAt=").append(createdAt);
        sb.append(", updatedAt=").append(updatedAt);
        sb.append(", paidAt=").append(paidAt);
        sb.append(", shippedAt=").append(shippedAt);
        sb.append(", completedAt=").append(completedAt);
        sb.append(", cancelledAt=").append(cancelledAt);
        sb.append("]");
        return sb.toString();
    }
}